package com.example.video

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.ParamSend
import com.example.base.entity.ParamSendChild
import com.example.base.entity.Reply
import com.example.base.entity.ReplyEntity
import com.example.base.entity.ReplyEntityItem
import com.example.base.mvvm.BaseViewModel
import com.example.base.mvvm.Res
import com.example.base.net.ApiServer
import kotlinx.coroutines.launch

class MainViewModel:BaseViewModel() {
    //返回值---获取评论
    val replySuccess = MutableLiveData<Res<ReplyEntity>>()
    val replyFail = MutableLiveData<String>()
    fun reply(datatype:Int,itemid:String){
        viewModelScope.launch {
            try {
                replySuccess.value = apiServer.reply(datatype, itemid)
            }catch (e:Exception){
                replyFail.value = e.message
            }
        }
    }
    //返回值--发送评论
    val sendSuccess = MutableLiveData<Res<ReplyEntityItem>>()
    val sendFail = MutableLiveData<String>()
    fun send(body:ParamSend){
        viewModelScope.launch {
            try {
                sendSuccess.value = apiServer.send(body)
            }catch (e:Exception){
                sendFail.value = e.message
            }
        }
    }
    //返回值--回复评论
    val sendChildSuccess = MutableLiveData<Res<Reply>>()
    val sendChildFail = MutableLiveData<String>()
    fun sendChild(body:ParamSendChild){
        viewModelScope.launch {
            try {
                sendChildSuccess.value = apiServer.sendChild(body)
            }catch (e:Exception){
                sendChildFail.value = e.message
            }
        }
    }
}